﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace AUV5.Web.Pages
{
    public partial class AccountList : PageBaseFrontend
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (base.IsVerified)
                {
                    BindData();
                }
                else
                {
                    Response.Redirect(URL_INDEX);
                }
               
            }
        }

        #region##绑定
        /// <summary>
        /// 绑定
        /// 创建人：Wilson
        /// 创建时间：2012-1-17
        /// </summary>
        private void BindData()
        {
            rptAccountList.DataSource = AUV5.BLL.UserAccountBLL.GetInstance().GetUserAccountList(VerifiedUserID);
            rptAccountList.DataBind();
        }
        #endregion

        #region##项点击
        /// <summary>
        /// 项点击
        /// 创建人：Wilson
        /// 创建时间：2012-1-17
        /// </summary>
        /// <param name="source"></param>
        /// <param name="e"></param>
        protected void rptAccountList_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            AUV5.Model.UserAccount account = AUV5.BLL.UserAccountBLL.GetInstance().GetDetail(Convert.ToString(e.CommandArgument));
            switch (e.CommandName)
            {
                case "disable":
                    account.State = Convert.ToInt32(AUV5.Common.Enum.auvState.Disable);
                    break;
                case "enable":
                    account.State = Convert.ToInt32(AUV5.Common.Enum.auvState.Enabled);
                    break;
            }

            int i = AUV5.BLL.UserAccountBLL.GetInstance().Update(account);

            if (i > 0)
            {
                Alert("修改成功");
                BindData();
            }
            else
            {
                Alert("修改失败");
            }
        }
        #endregion

        #region##项绑定
        /// <summary>
        /// 项绑定
        /// 创建人：Wilson
        /// 创建时间：2012-1-17
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void rptAccountList_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
            {
                Label lblState = e.Item.FindControl("lblState") as Label;
                LinkButton lbtnState = e.Item.FindControl("lbtnState") as LinkButton;
                Label lblAccountTypeId = e.Item.FindControl("lblAccountTypeId") as Label;
                Label lblAccountType = e.Item.FindControl("lblAccountType") as Label;

                switch (Convert.ToInt32(lblState.Text))
                {
                    case (int)AUV5.Common.Enum.auvState.Enabled:
                        lbtnState.CommandName = "disable";
                        lbtnState.Text = "禁用";
                        break;
                    case (int)AUV5.Common.Enum.auvState.Disable:
                        lbtnState.CommandName = "enable";
                        lbtnState.Text = "启用";
                        break;
                }

                AUV5.Model.AccountType type = AUV5.BLL.AccountTypeBLL.GetInstance().GetDetail(lblAccountTypeId.Text.Trim());

                if (type != null)
                {
                    lblAccountType.Text = type.AccountTypeName;
                }
            }
        }
        #endregion


    } 
}